package com.cirkana.serial;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class SerializationUtil {

	public static final byte[] serialize(SerializablePassData data)
			throws SerializationException {
		ByteArrayOutputStream bytes = new ByteArrayOutputStream();
		DataOutputStream out = new DataOutputStream(bytes);
		try {
			data.serialize(out);
			return bytes.toByteArray();
		} catch (IOException e) {
			throw new SerializationException(e);
		} finally {
			try {
				out.close();
			} catch (IOException e) {
				throw new SerializationException(e);
			}
			try {
				bytes.close();
			} catch (IOException e) {
				throw new SerializationException(e);
			}
		}
	}
}
